package org.vectrics.client.webclient;


import org.apache.log4j.*;
import java.util.*;



public abstract class CommunicationThread extends Thread {
	public static int GET_LATEST = 0;
	public static int GET_RANGE = 1;

	public static int ALL_LOGGERS_INTERVAL = 15;
	public static int LOGGER_LEVEL_INTERVAL = 8;
	public static int NEW_EVENTS_INTERVAL = 2;
	public static int OLD_EVENTS_INTERVAL = 3;
    
	public int allLoggersCounter = ALL_LOGGERS_INTERVAL;
	public int loggerLevelCounter = LOGGER_LEVEL_INTERVAL;
	public int newEventsCounter = 0;
	public int oldEventsCounter = 0;
	public int testLoggersCounter = 0;
    
    
	private int mission = GET_LATEST;
	private boolean stopped = false;
	private String serverAddress = "";
	private ServiceConnection connection = null;
	private ConnectionStatus connectStatus = ConnectionStatus.DISCONNECTED;
	private int requestCount = 0;
	private boolean testRequested = true;
	private Vector commands = new Vector();
    
	private transient static Logger log = Logger.getLogger(CommunicationThread.class);

	public CommunicationThread(ServiceConnection connection) {
		this.connection = connection;
	}
    
	public ServiceConnection getServerConnection() {
		return(connection);
	}
    
	public ConnectionStatus getConnectStatus() {
		return(connectStatus);
	}
    
	protected void setConnectStatus(ConnectionStatus connectStatus) {
		this.connectStatus = connectStatus;
	}
	
	public synchronized void addCommand(ServerCommand command) {
		commands.add(command);
	}
	
	public synchronized ServerCommand getNextCommand() {
		ServerCommand command = (ServerCommand)commands.elementAt(0);
		return(command);
	}
	
	public synchronized void removeCommand(ServerCommand command) {
		commands.removeElement(command);
	}
    
	public void doConnect(String url) {
	}
    
	public void runTests() {
		testRequested = true;
	}
    
	public abstract void run();

    
}
